var url = require('url')
 	,	querystring = require('querystring')
	 , 	negotiator = require('negotiator')
	 ,	globals = require('./globals.js');


var request = exports = module.exports = {};
    
request.getQueryStrings = function(req){
	querystring.parse(req.url);
};

request.formatters = '';

request.fillParams = function(req, regExp){
	console.log('Inside Request FillParams');
	req.params = {};
	var urlPath = url.parse(req.url).path;
	var args = urlPath.match(regExp);
	if((args[0] != undefined && args[0] !== null) && (url.parse(req.url).query === undefined || url.parse(req.url).query === null)){
		arguments = args[0].split('/');
		for(i = 1; i<arguments.length; i=i+2){
			req.params[arguments[i]] = arguments[i+1];
		}
	}
	else
	{
		req.params = url.parse(req.url, true).query;
	}
	console.log(req.params);
};

request.verifyContentType = function(req)
{
	globals.availablemediatypes.forEach(function(index, Element){
		
	});
}

request.negotiate = function(req){
	var negotiate = new negotiator(req);
	req.formatters = negotiate.mediaType(); 
};

request.header = function(name, value)
{
	name = name.toLowerCase();
	return (this.headers[name] || value);
}
